/*
flag 命令行参数解析

运行
cd src/base_pkg/cmd
go run flagTest.go -help
go run flagTest.go -name pprof --age 28 -married=false -d=1h30m

资料
https://www.topgoer.com/%E5%B8%B8%E7%94%A8%E6%A0%87%E5%87%86%E5%BA%93/flag.html

*/
package main

import (
	"flag"
	"fmt"
	"time"
)

func main() {
	//定义命令行参数方式1
	var name string
	var age int
	var married bool
	var delay time.Duration
	flag.StringVar(&name, "name", "张三", "姓名")
	flag.IntVar(&age, "age", 18, "年龄")
	flag.BoolVar(&married, "married", false, "婚否")
	flag.DurationVar(&delay, "d", 0, "延迟的时间间隔")

	//解析命令行参数
	flag.Parse()
	fmt.Println(name, age, married, delay)
	//返回命令行参数后的其他参数
	fmt.Println("flag.Args():", flag.Args())
	//返回命令行参数后的其他参数个数
	fmt.Println("flag.NArg()", flag.NArg())
	//返回使用的命令行参数个数
	fmt.Println("flag.NFlag()", flag.NFlag())
}
